Skip to content

Conversation

@MetRonnie
Copy link
Member

This change makes Ctrl+C during an interactive prompt more graceful - instead of giving traceback it will have the same effect as typing n+Enter

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • No dependency changes
  • Tests are included (or explain why tests are not needed).
  • Changelog entry included if this is a change that can affect users
  • Docs not needed
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@MetRonnie MetRonnie added this to the 8.7.0 milestone Oct 16, 2025
@MetRonnie MetRonnie self-assigned this Oct 16, 2025
@MetRonnie MetRonnie added small could be better Not exactly a bug, but not ideal. labels Oct 16, 2025
{'y': True, 'n': False},
process=str.lower,
)
with handle_sigint():
Copy link
Member

@oliver-sanders oliver-sanders Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use:

with suppress(KeyboardInterrupt):

Or:

try:
    ...
except KeyboardInterrupt:
    sys.exit(0)

(As appropriate)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that requires Ctrl+C twice while you are inside of the input() loop (or maybe doesn't work at all, can't remember), whereas this handles Ctrl+C immediately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

could be better Not exactly a bug, but not ideal. small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants